import java.io.*;

public class Test08 {
    public static void main(String[] args) throws IOException {
        File src=new File("D:\\aaa");
        File dest=new File("D:\\bbb");
        copydir(src,dest);
    }
    public static void copydir(File src,File dest) throws IOException {
        dest.mkdirs();
        File[] files=src.listFiles();
        if(files!=null){
            for(File file:files){
                if(file.isFile()){
                    FileInputStream fis=new FileInputStream(file);
                    FileOutputStream fos=new FileOutputStream(new File(dest,file.getName()));
                    int len;
                    byte[] bytes=new byte[1024];
                    while((len=fis.read(bytes))!=-1){
                        fos.write(bytes,0,len);
                    }
                    fis.close();
                    fos.close();
                }
                else{
                    copydir(file,new File(dest,file.getName()));
                }
            }
        }

    }
}
